﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Small.Util.Reflection;

namespace Small.UI
{
   public static class HtmlSubmit
    {

       public static MvcHtmlString Submit(this HtmlHelper helper,string id,string value=null,string name=null,object htmlAttribute=null) 
       {
           StringBuilder builder = new StringBuilder();


           builder.Append("<input type='submit' ");
           if (!string.IsNullOrEmpty(id)) 
           {
               builder.Append(string.Format(" id='{0}'", id));
           }
           if (string.IsNullOrEmpty(value)) 
           {
               value = "Submit";
           }

           builder.Append(string.Format("value='{0}'", value));
           if (htmlAttribute != null)
           {
               foreach (var item in AnonymousProperties.GetAnonymousInfomation(htmlAttribute))
               {
                   builder.Append(" " + item.Name + "=\"" + item.Value + "\"");

               }
           }

           builder.Append(" />");
           return new MvcHtmlString(builder.ToString());
       }
    }
}
